//
//  UIImage+Expand.h
//  Pension
//
//  Created by gavin on 2020/5/20.
//  Copyright © 2020 XLH. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN


typedef NS_ENUM(NSUInteger, MJCornerRadiusType) {
    MJCornerRadiusTypeTop,
    MJCornerRadiusTypeLeft,
    MJCornerRadiusTypeBottom,
    MJCornerRadiusTypeRight,
    MJCornerRadiusTypeTopLeftBottomRight,
    MJCornerRadiusTypeTopRightBottomLeft,
};

#pragma mark  IBInspectable
@interface UIView (IB)

/**
 设置view的圆角
 
 cornerRadius 圆角半径
 */
@property (nonatomic, assign)IBInspectable CGFloat mj_cornerRadius;

/**
 设置view的边框
 
 borderColorName 边框颜色
 */
@property (nonatomic, strong)IBInspectable NSString *mj_borderColorName;

/**
 设置view的边框
 
 borderWidth 边框大小
 */
@property (nonatomic, assign)IBInspectable CGFloat mj_borderWidth;

/// 背景颜色
@property (nonatomic, strong)IBInspectable NSString *mj_backgroundColorName;
@end

#pragma mark  Frame
@interface UIView (Frame)

@property(nonatomic, assign) CGFloat mj_top;

@property(nonatomic, assign) CGFloat mj_left;

@property(nonatomic, assign) CGFloat mj_bottom;

@property(nonatomic, assign) CGFloat mj_right;

@property(nonatomic, assign) CGFloat mj_width;

@property(nonatomic, assign) CGFloat mj_height;

@property (nonatomic, assign) CGPoint mj_origin;

@property (nonatomic, assign) CGSize mj_size;

@property (nonatomic, assign) CGFloat mj_centerX;

@property (nonatomic, assign) CGFloat mj_centerY;
@end

#pragma mark  UI
typedef void(^MJTouchGestureActionBlock)(void);
@interface UIView (MJUI)

/// 获取xib 视图
/// @param owner owner
+ (id)mj_loadNibWithOwner:(nullable id)owner;

/// 获取xib 视图
/// @param owner owner
+ (id)mj_nibInstantiateWithOwner:(nullable id)owner;

/// 添加点击事件
/// @param block 回调
- (void)mj_addTapActionWithBlock:(MJTouchGestureActionBlock)block;

/// 获取当前 view 所在的 UIViewController，注意使用场景不要过于频繁的调用
- (UIViewController *)mj_viewController;

/// 设置阴影 (只添加阴影，layer没有添加圆角)
/// @param offset 阴影偏移量
/// @param radius 阴影半径
/// @param color 阴影颜色
/// @param opacity 透明度
- (void)mj_dropShadowWithOffset:(CGSize)offset
                      radius:(CGFloat)radius
                       color:(UIColor *)color
                     opacity:(CGFloat)opacity;

/// 设置阴影 圆角 （对于没有子视图的控件,有子视图时不会切圆角）
///
/// - Parameters:
///   - color: 阴影颜色
///   - offset: 阴影偏移量
///   - opacity: 透明度
///   - cornerRadius: layer半径
///   - radius: 阴影半径
///   - rectCorner: 4角
- (void)mj_dropShadowWithOffset:(CGSize)offset
                cornerRadius:(CGFloat)cornerRadius
                      radius:(CGFloat)radius
                       color:(UIColor *)color
                     opacity:(CGFloat)opacity;

/// 圆角
/// @param radius 半径
- (void)mj_cornerRadius:(CGFloat)radius;

/// 边框的颜色和大小
/// @param color 颜色
/// @param width 宽度
- (void)mj_borderColor:(UIColor *)color width:(CGFloat)width;


/// 给任意UIView添加圆角（非图片），不是通过图片实现的。要求控件本身的frame是确定的，非自动布局才行。
/// @param corner 多个圆角可通过 UIRectCornerTopLeft | UIRectCornerTopRight 这样来使用
/// @param cornerRadius 圆角大小
- (void)mj_corner:(UIRectCorner)corner cornerRadius:(CGFloat)cornerRadius;

/// 任意圆角+绘制阴影
///
/// - Parameters:
///   - sColor: 阴影颜色
///   - offset: 阴影偏移量
///   - opacity: 透明度
///   - radius: layer半径
///   - sRadius: 阴影半径
///   - rectCorner: 4角
///   - bgColor: view的背景颜色
- (void)mj_corner:(UIRectCorner)corner sColor:(UIColor *)sColor offset:(CGSize)offset radius:(CGFloat)radius  sRadius:(CGFloat)sRadius opacity:(CGFloat)opacity bgColor:(UIColor *)bgColor;

/// 渐变
/// @param colors 渐变数组
/// @param startPoint 开始坐标
/// @param endPoint 结束坐标
/// @param locations 结束坐标
- (void)mj_gradientLayerWithColors:(NSArray *)colors startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint locations:(NSArray<NSNumber *> *)locations;

/// 渐变
/// @param colors 渐变数组
/// @param startPoint 开始坐标
/// @param endPoint 结束坐标
- (void)mj_gradientLayerWithColors:(NSArray *)colors startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint;

/// 设置任意圆角及边框(实线/虚线)
/// @param corners 要设置的圆角位置集合
/// @param radius 圆角半径
/// @param lineWidth 边框宽度
/// @param lineColor 边框颜色
/// @param lineDashPattern 虚线集合
- (void)mj_rounderWithCorners:(UIRectCorner)corners radius:(CGFloat)radius lineWidth:(CGFloat)lineWidth lineColor:(UIColor *_Nullable )lineColor dash:(NSArray<NSNumber *>*_Nullable )lineDashPattern;

/// 最顶层视图 Window
+ (UIWindow *)mj_topWindow;

/// 拷贝view
- (UIView *)mj_copyView;

/// 左右抖动
-(void)mj_shakeHor;

/// 切圆角
/// - Parameters:
///   - type: 方向
///   - cornerRadius: 半径
- (void)mj_cornerWithType:(MJCornerRadiusType)type cornerRadius:(CGFloat)cornerRadius;

/// view设置四个不同的圆角
/// - Parameters:
///   - topLeft: <#topLeft description#>
///   - topRight: <#topRight description#>
///   - bottomLeft: <#bottomLeft description#>
///   - bottomRight: <#bottomRight description#>
- (void)mj_cornerRadiusWithTopLeft:(CGFloat)topLeft topRight:(CGFloat)topRight bottomLeft:(CGFloat)bottomLeft bottomRight:(CGFloat)bottomRight;

/// 移除子视图
-(void)mj_removeAllSubviews;

/**
 ** lineView:       需要绘制成虚线的view
 ** lineLength:     虚线的宽度
 ** lineSpacing:    虚线的间距
 ** lineColor:      虚线的颜色
 **/
- (void)mj_drawDashlineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor;

/// 点击等待
/// - Parameters:
- (void)mj_clickAwaitWithTime:(CGFloat)awaitTime;

/// 设置背景图片
/// - Parameter imageNamed: 图片名称
- (void)mj_contentsWithImageNamed:(NSString *)imageNamed;

@end



#pragma mark  UICollectionView
@interface UICollectionView (Extend)
- (void)registerNibCell:(Class)cls;
@end

#pragma mark  UICollectionViewCell
@interface UICollectionViewCell (Extend)
+ (void)registerNibWithCollectionView:(UICollectionView *)collectionView;
+ (__kindof UICollectionViewCell *)reuseForCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath;
@end

#pragma mark  UICollectionReusableView
@interface UICollectionReusableView (Extend)
+ (void)registerHeaderNibWithCollectionView:(UICollectionView *)collectionView;
+ (nullable __kindof UICollectionReusableView *)reuseHeaderForCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath;

+ (void)registerFooterNibWithCollectionView:(UICollectionView *)collectionView;
+ (nullable __kindof UICollectionReusableView *)reuseFooterForCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath;
@end



#pragma mark  UITableView

@interface UITableView (Extend)
- (void)registerNibCell:(Class)cls;
- (void)registerNibHeadFoot:(Class)cls;
@end


#pragma mark  UITableViewCell
@interface UITableViewCell (Extend)
+ (void)registerNibWithTableView:(UITableView *)tableView;
+ (__kindof UITableViewCell *)reuseForTableView:(UITableView *)tableView forIndexPath:(NSIndexPath *)indexPath;
@end


#pragma mark  UITableViewHeaderFooterView

@interface UITableViewHeaderFooterView (Extend)
+ (void)registerNibWithTableView:(UITableView *)tableView;
+ (nullable __kindof UITableViewHeaderFooterView *)reuseForTableView:(UITableView *)tableView;
@end


NS_ASSUME_NONNULL_END
